package com.giscloud.limp.controller;

import java.util.Arrays;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;

import com.giscloud.limp.entity.LegalPublicity;
import com.giscloud.limp.service.LegalPublicityService;
import com.giscloud.limp.entity.dto.LegalPublicityDTO;
import com.giscloud.datasource.page.PageInfo;
import com.giscloud.commons.model.Result;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.*;


/**
 * 法制宣传
 *
 * @author giscloud
 * @email giscloud@giscloud.com
 * @date 2020-06-08 16:06:39
 */
@RestController
@RequestMapping("/limp/legalpublicity")
@Log4j2
public class LegalPublicityController {

    private final LegalPublicityService legalPublicityService;

    @Autowired
    public LegalPublicityController(LegalPublicityService legalPublicityService) {
        this.legalPublicityService = legalPublicityService;
    }
    /**
     * 列表
     */
    @RequestMapping("/list")
    public Result<PageInfo<LegalPublicity>> list(@RequestBody LegalPublicityDTO legalPublicityDTO){
        PageInfo page = legalPublicityService.queryPage(legalPublicityDTO);
        return Result.success(page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{legalPublicityId}")
    public Result<LegalPublicity> info(@PathVariable("legalPublicityId") Integer legalPublicityId){
		LegalPublicity legalPublicity = legalPublicityService.getById(legalPublicityId);
        return Result.success(legalPublicity);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public Result save(@RequestBody LegalPublicity legalPublicity){
        return legalPublicityService.save(legalPublicity);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public Result update(@RequestBody LegalPublicity legalPublicity){
        return legalPublicityService.updateById(legalPublicity);
    }

    /**
     * 删除(直接传数组对象即可，如：[1],[1,2]支持批量删除)
     */
    @RequestMapping("/delete")
    public Result delete(@RequestBody Integer[] legalPublicityIds){
        return legalPublicityService.removeByIds(Arrays.asList(legalPublicityIds));
    }

}
